package com.yuyou.fn.tradingservice.mapper;

import com.github.wens.mybatisplus.mapper.AutoMapper;
import com.yuyou.fn.tradingservice.entity.ServiceComment;
import com.yuyou.fn.tradingservice.vo.AvgEvaluation;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 *
 * ServiceComment 表数据库控制层接口
 *
 */
public interface ServiceCommentMapper extends AutoMapper<ServiceComment,Long> {
    @Select("<script>\n" +
            "SELECT \n" +
            " ROUND(AVG(grade1), 2) AS grade1,ROUND(AVG(grade2), 2) AS grade2, ROUND(AVG(grade3), 2) AS grade3  \n" +
            "from service_comment \n"+
            "<where>\n" +
            "<if test=\"query.productId != null \">\n" +
            "\tand product_id = #{query.productId}\n" +
            "</if>\n" +
            "<if test=\"query.categoryId != null \">\n" +
            "\tand category_id = #{query.categoryId}\n" +
            "</if>\n" +
            "</where>\n" +
            "</script>")
    AvgEvaluation findAvgByProductIdOrCategoryId(@Param("query") AvgEvaluation AvgEvaluation);
}